<template>
  <page-container>
    <search-form
      v-model="searchForm"
      :searchColumns="searchColumns"
      :searchOptions="{ menuSpan: 4 }"
      @on-search="handleSearch">
    </search-form>

    <avue-table
      :dataList="dataList"
      :loading="loading"
      :page="page"
      :tableColumns="tableColumns"
      :tableOptions="{ menuWidth: 80 }"
      @onPageChange="onPageChange">
      <template v-slot:menu="{ row }">
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="viewForm(row)"
          circle></el-button>
      </template>
    </avue-table>
  </page-container>
</template>

<script>
import tableMixins from '@/mixins/table'
import { deepClone } from '@/utils'
import { mapGetters } from 'vuex'
import { getFeedbackList } from '@/api/order'
import { searchColumns, tableColumns } from './config/table-config'
import { viewForms } from './config/dialog-config'

export default {
  mixins: [tableMixins],
  data() {
    return {
      dataList: [],
      childList: [],
      searchForm: {
        dateRange: [this.$startStamp(new Date()), this.$endStamp(new Date())],
      },
      editForm: {},
    }
  },
  computed: {
    ...mapGetters(['commonData']),
    userList() {
      return this.commonData?.userList ?? []
    },
    viewForms,
    searchColumns,
    tableColumns,
  },
  methods: {
    fetchMethod: getFeedbackList,

    // 查询参数格式化
    formatSearch() {
      const searchParams = deepClone(this.searchForm)
      const [start, end] = this.searchForm.dateRange
      searchParams.start = start && this.$dayjs(this.$startStamp(start)).unix()
      searchParams.end = end && this.$dayjs(this.$endStamp(end)).unix()
      delete searchParams.dateRange
      return searchParams
    },
    viewForm(res) {
      const parm = deepClone(res)
      parm.pictures = res?.pictures?.map(it => {
        return { value: it }
      })
      this.$dialogForm.show({
        title: '查看',
        data: parm,
        option: {
          submitBtn: false,
          span: 24,
          column: this.viewForms,
        },
      })
    },
  },
  mounted() {
    this.handleSearch()
  },
}
</script>

<style lang="scss" scoped></style>
